define(
    ["PDUtilDir/grid", "PDUtilDir/util", "PDUtilDir/tool", "PDUtilDir/slidebar", "PDUtilDir/inputSelect", "PDUtilDir/fileupload/multiFileUpload", "Date", "DateCN", "css!DateCss"],
    function (Grid, Util, Tool, Slidebar, inputSelect, MFU) {
        function updateSupportInit($scope, $compile) {
            return new updateSupport($scope, $compile);
        };

        function updateSupport($scope, $compile) {
            this.$scope = $scope;
            this.$compile = $compile;
        };
        updateSupport.fn = updateSupport.prototype;

        updateSupport.fn.init = function (id) {
            var _this = this,
                allData = this.$scope.grid.getAllData();

            $.each(allData, function (index, row) {
                if (row.id == id) {
                    _this.entity = $.extend(row, {
                        carTypeName: _this.$scope.cache.typeMap.get(row.carType)
                    });
                    return;
                }
            });
        };

        updateSupport.fn.digest = function () {
            this.$scope.$digest();
        };

        updateSupport.fn.run = function (id) {
            var _this = this;
            _this.init(id);

            this.slidebars = Slidebar({
                size: 'lg',
                url: getServer()
                + "/static/app/fleet/cteamOrderInfos/views/update.html",
                $scope: this.$scope,
                $compile: this.$compile,
                afterLoad: function ($Panel) {
                    _this.initialization();
                    _this.digest();
                }
            });
        };
        updateSupport.fn.initialization = function () {
            this.baseInit();
            this.carInfoInit();
        };
        updateSupport.fn.baseInit = function () {
            var _this = this;
        };
        updateSupport.fn.save = function() {
            var _this = this;
            $.ajax({
                url : getServer() + "/flea/hclv/car/reserve/update/apply/add.htmls",
                data : {
                    'model' : JSON.stringify(_this.entity)
                },
                success : function(data) {
                    if (data.status != 200) {
                        return;
                    }
                    _this.$scope.grid.refresh();
                    Util.alert(data.message);
                    _this.slidebars.close();
                }
            });
        };
        updateSupport.fn.carInfoInit = function () {
            Grid({
                id : "CarTeamReserveDetailGirdDivId",
                pageSize : 10,
                index : true,
                multi : true,
                pagination : true,
                cache : false,
                layout : [ {
                    name : "车队名称",
                    field : "provideDeptName",
                    sort : true,
                    click : function(e) {
                        updateSupport.run(e.data.row);
                    }
                }, {
                    name : "车辆类型",
                    field : "carType",
                    sort : true,
                    format:function(e){
                        return cache.typeMap.get(e.row.carType);
                    }
                }, {
                    name : "数量",
                    field : "carNumber",
                    width : "10%"
                }, {
                    name : "预定状态",
                    field : "reserveStatus",
                    format:function(e){
                        return cache.statuMap.get(e.row.status);
                    }
                }, {
                    name : "支付状态",
                    field : "status",
                    format:function(e){
                        return cache.statuMap.get(e.row.status);
                    }
                }, {
                    name : "总费用",
                    field : "totalCost",
                    width : "10%"
                }, {
                    name : "使用时间",
                    field : "useDate",
                    width : "10%"
                }, {
                    name : "归还时间",
                    field : "useDate",
                    width : "10%"
                }],
                toolbar : [ ],
                data : this.entity.cars
            });
        };
        return updateSupportInit;
    });